<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="750" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="right">

            <el-form-item label="活动名称" prop="name">
				<el-input v-model="form.name" clearable placeholder=""></el-input>
			</el-form-item>
            <el-form-item label="活动简介" prop="des">
				<el-input v-model="form.des" clearable placeholder=""></el-input>
			</el-form-item>
            <el-form-item label="开始时间" prop="stime">
				<el-date-picker
				    v-model="form.stime"
				    type="datetime"
				    placeholder="选择时间">
				</el-date-picker>

			</el-form-item>
            <el-form-item label="结束时间" prop="etime">
				<el-date-picker
				    v-model="form.etime"
				    type="datetime"
				    placeholder="选择时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="每人可抽次数" prop="chou_num">
				<el-input v-model="form.chou_num" clearable placeholder="为空或0 则表示无限制"></el-input>
			</el-form-item>
			<el-form-item label="显示" prop="sort">
				<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
			</el-form-item>

		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
    import { defineAsyncComponent } from 'vue';
	const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
	export default {
		components: {
			scEditor
		},
		emits: ['success', 'closed'],
		data() {
			return {
				goods:[],
				mode: "add",
				titleMap: {
					add: '创建抽奖活动',
					edit: '编辑',
					show: '查看'
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					status:'1'
                },
				//验证规则
				rules: {
					pid: [
						{required: true, message: '请选择商品'}
					],
                    ex_jifen:[
                       {required: true, message: '请输入兑换积分'}
                    ]
				}
			}
		},
		mounted() {

		},
		methods: {

			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res = await this.$API.system.universal.handle.post(this.form,'/mk/turntable_save');
						this.isSaveing = false;
						if(res.code == 200){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			},
			//表单注入数据
			setData(data){
				if(this.mode == 'edit'){
					 this.guigelist = data.guigedata
					 this.guige = data.guige==1?true:false
				}
				this.form = data
			}
		}
	}
</script>

<style>
</style>
